package com.woniuxy.hrp.mapper;

import com.woniuxy.hrp.entity.Wallet;
import com.woniuxy.hrp.provider.WalletProvide;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface WalletMapper {
    /**
     * desc: 增加钱包（注册用户时钱包一起生成）
     * @Param: [wallet]
     * @Return: [com.woniuxy.hrp.entity.Wallet]
     * @Author: caojieke
     * @Date: 2022/8/29 20:49
     */
    @Insert("insert hrp_wallet (balance,patient_id) values (#{balance},#{patient.id})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    public void insert(Wallet wallet);
    /**
     * desc:修改钱包信息（对钱包余额进行修改）
     * @Param:  * @param wallet
     * @Return: [com.woniuxy.hrp.entity.Wallet]
     * @Author: caojieke
     * @Date: 2022/8/29 20:48
     */
    @UpdateProvider(type = WalletProvide.class,method = "update")
    public void update(Wallet wallet);
    /**
     * desc: 获取钱包信息
     * @Param: [wallet]
     * @Return: [com.woniuxy.hrp.entity.Wallet]
     * @Author: caojieke
     * @Date: 2022/8/29 20:47
     */
    public Wallet getWallet(Wallet wallet);
    //通过患者ID查询钱包余额
    @Select("select * from hrp_wallet where patient_id=#{patientid}")
    Wallet getByPatientId(int patientid);

    /***
     * @description:根据患者id查钱包，一对多带出钱包操作记录
     * @param: id
     * @return: com.woniuxy.hrp.entity.Wallet
     * @author Lrw
     * @date: 2022/9/7 10:26
     */
    @Select("select * from hrp_wallet where patient_id=#{patientId}")
    @Results({
            @Result(column = "id",property = "id",id = true),
            @Result(column = "id",property = "walletoprs",many = @Many(select = "com.woniuxy.hrp.mapper.WalletoprMapper.selectByWalletId")),
    })
    Wallet selectById(int patientId);
}
